<header id="topbar">
    <div class="topbar-left">
        <ol class="breadcrumb">
            <li class="crumb-active">
                <a href="<%= window.location.href %>">每日商品活动</a>
            </li>
        </ol>
    </div>
</header>
<section id="content">
    <div class="panel">
        <form class="form-horizontal" role="form" id="searchBox">
            <div class="form-group">
                <label for="dateFilter" class="col-md-1 control-label">日期：</label>
                <div class="col-md-4">
                    <input type="text" id="dateFilter" class="form-control text-center" value="<%= options.date_range[0] %> ~ <%= options.date_range[1] %>">
                </div>
                <label class="col-md-1 control-label">商品类型：</label>
                <div class="col-md-2">
                    <select class="form-control" id="inputCategory" data-field="category" data-useless="">
                            <option value="">所有类型</option>
                        <% _.each(GOODS_CUSTUM_CATEGORY, function(v, k){ %>
                            <option value="<%= k %>" <%= options.category == k ? "selected" : "" %>> <%= v %> </option>
                        <% }) %>
                    </select>
                </div>
                <label class="col-md-1 control-label">显示方式：</label>
                <div class="col-md-2">
                    <select class="form-control" id="inputMode" data-field="mode" date-type="int">
                        <option value="2" <%= options.mode == 2 ? "selected" : "" %>>每日</option>
                        <option value="0" <%= options.mode == 0 ? "selected" : "" %>>总值(按类型)</option>
                        <option value="1" <%= options.mode == 1 ? "selected" : "" %>>均值(按类型)</option>
                    </select>
                </div>
                <div class="col-md-1">
                    <input type="button" id="search" class="btn btn-primary btn-block form-control" value="提交">
                </div>
            </div>
        </form>
    </div>

    <div class="panel overflow">
        <div class="panel-heading">
            <span class="panel-icon"><i class="fa fa-gear text-primary"></i>
            </span>
            <span class="panel-title">数据表格</span>
        </div>
        <div class="panel-body">
            <table class="table table-striped fs13">
            <% if(options.mode == 0 || options.mode == 1 || (options.category != null && options.mode == 2)){ %>
                <thead>
                    <tr class="bg-light">
                        <% if(options.mode == 2){ %>
                            <th>日期</th>
                        <% } %>
                        <th>类型</th>
                        <th>参与人数</th>
                        <th>购买人次</th>
                        <th>开奖次数</th>
                        <th>中奖次数</th>
                        <th>中奖金额</th>
                        <th>开奖成本</th>
                        <th>利润率</th>
                    </tr>
                </thead>
                <tbody class="admin-form">
                    <% _.each(items, function(item){ %>
                        <tr>
                            <% if(options.mode == 2){ %>
                                <th><%= item.day %></th>
                            <% } %>
                            <td><%= GOODS_CUSTUM_CATEGORY[item._id] %></td>
                            <td><%= item.real_payer_count %></td>
                            <td><%= item.real_pay_amount || 0 %></td>
                            <td><%= (item.virtual_win_count || 0) + (item.real_win_count || 0) %></td>
                            <td><%= item.real_win_count || 0 %></td>
                            <td><%= (item.real_win_amount || 0).toFixed(2) %></td>
                            <td><%= (item.real_win_target || 0).toFixed(2) %></td>
                            <td><%= ((item.profit_rate || 0) * 100).toFixed(2) %>%</td>
                        </tr>
                    <% }) %>
                </tbody>
            <% }else if(options.mode == 2){ %>
                <thead>
                    <tr class="bg-light">
                        <th>日期</th>
                        <th>开奖商品数量</th>
                        <th>开奖商品金额</th>
                        <th>开奖商品成本</th>
                        <th>自有用户参与人数</th>
                        <th>自有用户参与人次</th>
                        <th>自有用户中奖数量</th>
                        <th>自有用户中奖人数</th>
                        <th>自有用户中奖金额</th>
                        <th>自有用户中奖金额占比</th>
                        <th>渠道用户参与人数</th>
                        <th>渠道用户参与人次</th>
                        <th>渠道用户中奖数量</th>
                        <th>渠道用户中奖人数</th>
                        <th>渠道用户中奖金额</th>
                        <th>渠道用户中奖金额占比</th>
                        <th>渠道用户中奖成本</th>
                    </tr>
                </thead>
                <tbody class="admin-form">
                    <% _.each(items, function(item){
                        var total_amount = ((item.real_win_amount || 0) + (item.virtual_win_amount || 0)).toFixed(2);%>
                        <tr>
                            <td><%= item._id %></td>
                            <td><%= (item.virtual_win_count || 0) + (item.real_win_count || 0) %></td>
                            <td><%= ((item.virtual_win_target || 0) + (item.real_win_target || 0)).toFixed(2) %></td>
                            <td><%= total_amount %></td>
                            <td><%= item.virtual_payer_count || 0 %></td>
                            <td><%= item.virtual_pay_amount %></td>
                            <td><%= item.virtual_win_count || 0 %></td>
                            <td><%= item.virtual_winner_count || 0 %></td>
                            <td><%= (item.virtual_win_amount || 0).toFixed(2) %></td>
                            <td><%= total_amount > 0 ? (item.virtual_win_amount * 100 / total_amount).toFixed(2) : 0 %>%</td>
                            <td><%= item.real_payer_count || 0 %></td>
                            <td><%= item.real_pay_amount %></td>
                            <td><%= item.real_win_count %></td>
                            <td><%= item.real_winner_count || 0 %></td>
                            <td><%= (item.real_win_amount || 0).toFixed(2) %></td>
                            <td><%= total_amount > 0 ? (item.real_win_amount * 100 / total_amount).toFixed(2) : 0 %>%</td>
                            <td><%= (item.real_win_target || 0).toFixed(2) %></td>
                        </tr>
                    <% }) %>
                </tbody>
            <% } %>
            </table>
        </div>
    </div>

    <% if(options.mode == 0 || options.mode == 1 || (options.category != null && options.mode == 2)){ %>
    <div class="panel">
        <div class="panel-heading">
            <span class="panel-icon"><i class="fa fa-gear text-primary"></i>
            </span>
            <span class="panel-title">绘制图形</span>
        </div>
        <div class="panel-body">
            <form class="form-horizontal" role="form">
                <label for="inputColumn" class="control-label col-md-1">选择绘制列：</label>
                <div class="col-md-2">
                    <select id="inputColumn" class="form-control">
                        <option value="real_payer_count">参与人数</option>
                        <option value="real_pay_amount">购买人次</option>
                        <option value="real_win_amount">中奖金额</option>
                        <option value="real_win_target">开奖成本</option>
                        <option value="profit_rate">利润率</option>
                    </select>
                </div>
                <div class="col-md-1">
                    <input type="button" id="paint" class="btn btn-primary btn-block form-control" value="提交">
                </div>
            </form>
            <div id="chart"></div>
        </div>
    </div>
    <% } %>
</section>
